<style>
.pure_form_extra .mandatory { color: #ff0000; padding-left: 5px; }
</style>

<?php 
$opts = new stdClass();
$opts->cd = 't.id = :v1';
$opts->cdv = array(':v1' => $user->id);
$data = $orm->get('pb_colg_user', NULL, NULL, NULL, NULL, $opts)->d;

$pg = Utils::get_param('pg', 1);
$objs = $orm->get('pb_colg_user', 't.first_name', 'ASC', $pg, SIZE, NULL);

$uts = unserialize(UTS);

?>
<div class="pure-form pure-form-aligned pure_form_extra" style="padding: 10px; width: 480px;">
  <legend>Profile</legend>
  
  <div class="pure-control-group">
    <label>Account<span class="mandatory">*</span></label>
    <input id="account" type="text" class="pure-input-1-2" placeholder="{Account}" readonly="true"/>
  </div>
  
  <div class="pure-control-group">
    <label>Password<span class="mandatory">*</span></label>
    <input id="password" type="password" class="pure-input-1-2" placeholder="{Password}" />
  </div>

  <div class="pure-control-group">
    <label>First Name<span class="mandatory">*</span></label>
    <input id="first_name" type="text" class="pure-input-1-2" placeholder="{First Name}" />
  </div>
  
  <div class="pure-control-group">
    <label>Last Name</label>
    <input id="last_name" type="text" class="pure-input-1-2" placeholder="{Last Name}" />
  </div>
  
  <div class="pure-control-group">
    <label>Email</label>
    <input id="email" type="text" class="pure-input-1-2" placeholder="{Email}" />
  </div>
  
  <div class="pure-control-group">
    <label>&nbsp;</label>
    <button class="pure-button pure-input-1-2 pure-button-primary" onclick="submit_obj();">Save</button>
  </div>
</div>

<script type="text/javascript">
  /*<![CDATA[*/
  var __objs = JSON.parse('<?php echo addslashes(json_encode($objs)); ?>');
  var __data = JSON.parse('<?php echo addslashes(json_encode($data)); ?>');
  var __dir = '<?php echo PLGN_DIR . basename(dirname(__FILE__)); ?>';
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __file = '<?php echo addslashes($app_data->param_file); ?>';
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  var __id = '<?php echo $app_data->param_id; ?>';
  var __session_id = '<?php echo session_id(); ?>';
  var __tmp = null;
  
  $(function() {
    reset();
    render();
  });
  
  function reset() {
  };

  function render() {
    render_data();
  };
  
  function render_data() {
    Url.insert_param('id', __data[0].id);
    $('#account').val(__data[0].account);
    $('#password').val('');
    $('#first_name').val(__data[0].first_name);
    $('#last_name').val(__data[0].last_name);
    $('#email').val(__data[0].email);
  };

  function submit_obj() {
    req = __data[0];
    req.__password = $('#password').val();
    req.first_name = $('#first_name').val();
    req.last_name = $('#last_name').val();
    req.email = $('#email').val();
    req.__pg = __objs.p;
    
    Ajax.request(
      __requrl + 'submit_obj',
      'req=' + Utils.encodeURI(JSON.stringify(req)),
      function(rslt) {
        if (rslt.__objs) {
          __objs = rslt.__objs;
          delete rslt.__objs;
        }
        __data[0] = rslt;
        render();
      },
      null
    );
  };
  /*]]>*/
</script>